#include <gmlib/aes/aes_mode.h>

#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace aes;
using namespace block_cipher_mode;

static bool test_AES128EcbEncryptor();
static bool test_AES128EcbDecryptor();
static bool test_AES128CbcEncryptor();
static bool test_AES128CbcDecryptor();
static bool test_AES128CfbEncryptor();
static bool test_AES128CfbDecryptor();
static bool test_AES128OfbEncryptor();
static bool test_AES128OfbDecryptor();
static bool test_AES128CtrEncryptor();
static bool test_AES128CtrDecryptor();

static bool test_AES192EcbEncryptor();
static bool test_AES192EcbDecryptor();
static bool test_AES192CbcEncryptor();
static bool test_AES192CbcDecryptor();
static bool test_AES192CfbEncryptor();
static bool test_AES192CfbDecryptor();
static bool test_AES192OfbEncryptor();
static bool test_AES192OfbDecryptor();
static bool test_AES192CtrEncryptor();
static bool test_AES192CtrDecryptor();

static bool test_AES256EcbEncryptor();
static bool test_AES256EcbDecryptor();
static bool test_AES256CbcEncryptor();
static bool test_AES256CbcDecryptor();
static bool test_AES256CfbEncryptor();
static bool test_AES256CfbDecryptor();
static bool test_AES256OfbEncryptor();
static bool test_AES256OfbDecryptor();
static bool test_AES256CtrEncryptor();
static bool test_AES256CtrDecryptor();

#define TEST(func)                                                     \
    if (!test_##func())                                                \
    {                                                                  \
        fprintf(stderr, "err in test %s, line %d\n", #func, __LINE__); \
        throw std::runtime_error("err in " #func);                     \
    }

void test_aes_mode()
{
    TEST(AES128EcbEncryptor);
    TEST(AES128EcbDecryptor);
    TEST(AES128CbcEncryptor);
    TEST(AES128CbcDecryptor);
    TEST(AES128CfbEncryptor);
    TEST(AES128CfbDecryptor);
    TEST(AES128OfbEncryptor);
    TEST(AES128OfbDecryptor);
    TEST(AES128CtrEncryptor);
    TEST(AES128CtrDecryptor);

    TEST(AES192EcbEncryptor);
    TEST(AES192EcbDecryptor);
    TEST(AES192CbcEncryptor);
    TEST(AES192CbcDecryptor);
    TEST(AES192CfbEncryptor);
    TEST(AES192CfbDecryptor);
    TEST(AES192OfbEncryptor);
    TEST(AES192OfbDecryptor);
    TEST(AES192CtrEncryptor);
    TEST(AES192CtrDecryptor);

    TEST(AES256EcbEncryptor);
    TEST(AES256EcbDecryptor);
    TEST(AES256CbcEncryptor);
    TEST(AES256CbcDecryptor);
    TEST(AES256CfbEncryptor);
    TEST(AES256CfbDecryptor);
    TEST(AES256OfbEncryptor);
    TEST(AES256OfbDecryptor);
    TEST(AES256CtrEncryptor);
    TEST(AES256CtrDecryptor);
}

static uint8_t user_key[32] = {
    0x04, 0xb5, 0xf0, 0x47, 0x03, 0xe2, 0x02, 0x5f, 0x5d, 0x08, 0x46,
    0xc8, 0x0a, 0x68, 0x19, 0xa0, 0x04, 0xb5, 0xf0, 0x47, 0x03, 0xe2,
    0x02, 0x5f, 0x5d, 0x08, 0x46, 0xc8, 0x0a, 0x68, 0x19, 0xa0,
};

static uint8_t iv[16] = {
    0x04, 0xb5, 0xf0, 0x47, 0x03, 0xe2, 0x02, 0x5f,
    0x5d, 0x08, 0x46, 0xc8, 0x0a, 0x68, 0x19, 0xa0,
};

static uint8_t pt[] = {
    0x13, 0xf1, 0xdb, 0xd4, 0x4e, 0x92, 0x3a, 0x83, 0xd0, 0x23, 0x29, 0x7d,
    0xb0, 0x72, 0x59, 0x22, 0x12, 0x9f, 0x6f, 0xff, 0xc1, 0x85, 0x11, 0xde,
    0x69, 0xcf, 0xca, 0x6f, 0x9a, 0xf5, 0xdc, 0x42, 0xcf, 0x85, 0x56, 0x0a,
    0x54, 0x42, 0xdd, 0x96, 0x36, 0x6b, 0x80, 0x22, 0x6d, 0x23, 0x19, 0x36,
    0xa4, 0x88, 0x3d, 0xc9, 0x7a, 0x46, 0x88, 0x4d, 0x6f, 0x2a, 0xd6, 0x83,
    0xc9, 0xbd, 0xa5, 0x29, 0x02, 0x20, 0xaa, 0xb3, 0x8c, 0xaa, 0xa2, 0x71,
    0x45, 0x0b, 0x23, 0x1b, 0x6b, 0x26, 0x7d, 0x8a, 0x37, 0x7d, 0x77, 0xb0,
    0xfd, 0xbb, 0x90, 0xaf, 0x98, 0xc5, 0xda, 0xdd, 0x18, 0x63, 0x0d, 0x02,
    0xe8, 0x7a, 0x07, 0x58, 0xe4, 0xda, 0x47, 0x7c, 0x24, 0xe2, 0x9a, 0x99,
    0xfd, 0xd8, 0x20, 0x4e, 0x8a, 0x77, 0xeb, 0x77, 0xbf, 0x47, 0x0b, 0x23,
    0xaf, 0xd1, 0x20, 0x4c, 0xc8, 0xfa, 0x8b, 0x71,
};

// ****************************************
// ********** Test AES128 *****************
// ****************************************

#pragma region "AES128"

static uint8_t ct128[] = {
    0x05, 0x82, 0x59, 0x7a, 0xc7, 0x32, 0xc6, 0xaf, 0x3a, 0x0f, 0xee, 0xe1,
    0x8d, 0xd1, 0x32, 0xa5, 0x6f, 0x86, 0x9e, 0x2b, 0x33, 0xa4, 0xe7, 0x88,
    0xc7, 0xbc, 0x40, 0xd4, 0xd7, 0x71, 0x78, 0x18, 0x60, 0x46, 0x5e, 0x44,
    0x70, 0x86, 0x1e, 0x08, 0x1b, 0xc6, 0xa6, 0x09, 0x25, 0xe9, 0x7c, 0xf3,
    0xc4, 0x7a, 0x21, 0x79, 0xf4, 0x71, 0x3c, 0xb9, 0xc5, 0x3a, 0xed, 0xf4,
    0x35, 0x9f, 0x4c, 0x09, 0xc1, 0x45, 0xaa, 0x6d, 0xc0, 0x94, 0x6f, 0xf2,
    0xee, 0x29, 0xa6, 0xb5, 0xd6, 0xab, 0x6d, 0xf7, 0x46, 0x6c, 0xb9, 0x8d,
    0x13, 0x1b, 0xeb, 0x81, 0xdd, 0x76, 0xd3, 0x2d, 0xab, 0x39, 0xc4, 0x32,
    0x71, 0xb8, 0x68, 0xc3, 0x4e, 0x5f, 0x14, 0x3b, 0xad, 0xbe, 0x36, 0x8b,
    0x0a, 0x11, 0x7d, 0x05, 0x85, 0xe7, 0x6c, 0x00, 0x83, 0xf4, 0x09, 0x90,
    0x35, 0xf5, 0xf4, 0xce, 0x98, 0xe8, 0x5d, 0x79,
};

static uint8_t ecb_ct128[] = {
    0x05, 0x82, 0x59, 0x7a, 0xc7, 0x32, 0xc6, 0xaf, 0x3a, 0x0f, 0xee, 0xe1,
    0x8d, 0xd1, 0x32, 0xa5, 0x6f, 0x86, 0x9e, 0x2b, 0x33, 0xa4, 0xe7, 0x88,
    0xc7, 0xbc, 0x40, 0xd4, 0xd7, 0x71, 0x78, 0x18, 0x60, 0x46, 0x5e, 0x44,
    0x70, 0x86, 0x1e, 0x08, 0x1b, 0xc6, 0xa6, 0x09, 0x25, 0xe9, 0x7c, 0xf3,
    0xc4, 0x7a, 0x21, 0x79, 0xf4, 0x71, 0x3c, 0xb9, 0xc5, 0x3a, 0xed, 0xf4,
    0x35, 0x9f, 0x4c, 0x09, 0xc1, 0x45, 0xaa, 0x6d, 0xc0, 0x94, 0x6f, 0xf2,
    0xee, 0x29, 0xa6, 0xb5, 0xd6, 0xab, 0x6d, 0xf7, 0x46, 0x6c, 0xb9, 0x8d,
    0x13, 0x1b, 0xeb, 0x81, 0xdd, 0x76, 0xd3, 0x2d, 0xab, 0x39, 0xc4, 0x32,
    0x71, 0xb8, 0x68, 0xc3, 0x4e, 0x5f, 0x14, 0x3b, 0xad, 0xbe, 0x36, 0x8b,
    0x0a, 0x11, 0x7d, 0x05, 0x85, 0xe7, 0x6c, 0x00, 0x83, 0xf4, 0x09, 0x90,
    0x35, 0xf5, 0xf4, 0xce, 0x98, 0xe8, 0x5d, 0x79,
};

static uint8_t cbc_ct128[] = {
    0x47, 0x80, 0x57, 0xa9, 0x11, 0x3e, 0x05, 0x7f, 0x7e, 0x0e, 0xf6, 0x50,
    0x54, 0xb1, 0x1e, 0x74, 0xde, 0x0c, 0xd8, 0xb7, 0x9b, 0x71, 0x3a, 0x3e,
    0x8d, 0x6e, 0xd4, 0x38, 0x59, 0x74, 0x6d, 0x54, 0x78, 0xd9, 0x19, 0x78,
    0x88, 0xd5, 0x9b, 0x85, 0x8b, 0x59, 0x85, 0xcb, 0x29, 0xc5, 0x6e, 0xdb,
    0xdb, 0xa5, 0x35, 0xb5, 0x0f, 0x40, 0x95, 0x27, 0x6e, 0x64, 0x30, 0x59,
    0x64, 0xfe, 0x0d, 0x87, 0x62, 0x2c, 0xb6, 0x21, 0x1f, 0xc2, 0x06, 0x2c,
    0xf4, 0xaf, 0x33, 0xc7, 0xe6, 0xeb, 0x08, 0x28, 0xef, 0xb6, 0x37, 0xd9,
    0x06, 0xfe, 0xd5, 0xff, 0x88, 0x89, 0xc7, 0x90, 0xb7, 0x84, 0xc5, 0x72,
    0xb2, 0x58, 0x5f, 0x4e, 0x86, 0xd6, 0xf6, 0x84, 0x6d, 0x72, 0x6c, 0xf6,
    0xdb, 0x50, 0x62, 0xa1, 0xac, 0x02, 0xa5, 0xee, 0x04, 0xa4, 0x70, 0x68,
    0xf2, 0xf1, 0xa0, 0xc4, 0x47, 0x62, 0xd9, 0xe8,
};

static uint8_t cfb_ct128[] = {
    0xed, 0x93, 0x11, 0x7d, 0x32, 0x7b, 0xda, 0x8d, 0xb0, 0x93, 0x73, 0x15,
    0x17, 0x52, 0xff, 0x31, 0x9c, 0xfd, 0xad, 0xf9, 0x95, 0x03, 0x4e, 0xa0,
    0xdd, 0x15, 0x7f, 0x37, 0x71, 0x28, 0x34, 0x29, 0xdb, 0x26, 0xea, 0xb4,
    0xf5, 0xf1, 0x32, 0xff, 0xad, 0x32, 0x06, 0xc3, 0xf3, 0x2f, 0x98, 0x9e,
    0x52, 0xcd, 0xfd, 0x98, 0xaf, 0xbd, 0x7b, 0x86, 0xb4, 0xb2, 0x29, 0x49,
    0x01, 0xa8, 0x2b, 0x7a, 0xbd, 0x19, 0x9d, 0x35, 0x15, 0x95, 0x98, 0x6b,
    0x21, 0xc2, 0xb4, 0xbf, 0xb7, 0xe8, 0x18, 0xd8, 0x6b, 0x0a, 0x23, 0xff,
    0x20, 0xea, 0x90, 0xd8, 0xe5, 0xb0, 0x0b, 0xb1, 0x86, 0x4d, 0xfe, 0xc3,
    0xe6, 0xb5, 0x03, 0xe7, 0xf6, 0x60, 0xcf, 0x86, 0x25, 0x25, 0x33, 0x4e,
    0x92, 0xb6, 0x9e, 0x5a, 0x6a, 0xb0, 0xfd, 0x4b, 0xc7, 0xcd, 0xe5, 0x47,
    0x18, 0xaf, 0xc3, 0x13, 0x8d, 0x76, 0xd2, 0x14,
};

static uint8_t ofb_ct128[] = {
    0xed, 0x93, 0x11, 0x7d, 0x32, 0x7b, 0xda, 0x8d, 0xb0, 0x93, 0x73, 0x15,
    0x17, 0x52, 0xff, 0x31, 0x6a, 0xa0, 0x76, 0xa3, 0x1b, 0xd6, 0x66, 0x38,
    0x27, 0xb0, 0x54, 0x0f, 0x49, 0xfb, 0xc4, 0xcf, 0x7e, 0x72, 0x3c, 0x3e,
    0x83, 0x9b, 0xf4, 0x12, 0x57, 0x01, 0xa1, 0x37, 0x41, 0x13, 0x5b, 0x62,
    0x9c, 0xfa, 0x3e, 0xfd, 0x72, 0xab, 0x9e, 0x41, 0x65, 0xef, 0xea, 0x0c,
    0x19, 0x3c, 0x1d, 0xb8, 0x55, 0xc7, 0x23, 0xd9, 0x7a, 0x26, 0xd1, 0x04,
    0x5c, 0xeb, 0x97, 0x8e, 0xd2, 0x01, 0x1f, 0x55, 0x1d, 0xb3, 0x04, 0xcb,
    0xa8, 0x08, 0x01, 0x79, 0xe2, 0x27, 0xdb, 0x60, 0xd9, 0x88, 0x99, 0x30,
    0x28, 0x54, 0xfd, 0x06, 0x41, 0x71, 0x83, 0x2f, 0xaa, 0x3c, 0xd3, 0x87,
    0xe2, 0x64, 0x2d, 0x5f, 0x54, 0x06, 0xba, 0x17, 0xa2, 0x87, 0xec, 0xc8,
    0xea, 0x5f, 0xe3, 0x80, 0x32, 0xbb, 0xe7, 0x56,
};

static uint8_t ctr_ct128[] = {
    0xed, 0x93, 0x11, 0x7d, 0x32, 0x7b, 0xda, 0x8d, 0xb0, 0x93, 0x73, 0x15,
    0x17, 0x52, 0xff, 0x31, 0x54, 0x23, 0x29, 0x74, 0xad, 0xab, 0x11, 0xef,
    0x31, 0xe0, 0x61, 0x7a, 0xbb, 0x23, 0x00, 0xb0, 0xb7, 0xa1, 0x84, 0xed,
    0xad, 0xa4, 0x8c, 0x33, 0x06, 0x86, 0x25, 0xfd, 0x9a, 0xc8, 0x2e, 0x53,
    0x24, 0x40, 0x60, 0x3a, 0x06, 0x1c, 0x04, 0xc5, 0xe8, 0xe7, 0xcf, 0x49,
    0x58, 0x5c, 0xac, 0x3b, 0x75, 0x9a, 0xd9, 0xea, 0xd8, 0x25, 0xac, 0x5d,
    0x29, 0x32, 0x92, 0xdb, 0x18, 0xa3, 0xac, 0x03, 0x4d, 0x3e, 0x00, 0x84,
    0x41, 0x1e, 0x8e, 0xb4, 0x6f, 0x6c, 0x26, 0x16, 0x9a, 0x73, 0x94, 0x69,
    0xc3, 0x06, 0x7a, 0xcd, 0xfd, 0xc0, 0x60, 0x82, 0xea, 0xb0, 0x05, 0x1f,
    0xc5, 0xd1, 0x46, 0xd5, 0x63, 0xe6, 0x28, 0xd2, 0x25, 0xf5, 0x10, 0xba,
    0x3d, 0xa6, 0x46, 0xe4, 0x49, 0x37, 0x80, 0x80,
};

static bool test_AES128EcbEncryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     encryptor          = EcbEncryptor<AES128>(user_key);
    uint8_t* outptr             = buffer;
    size_t   outl;
    encryptor.update(outptr, &outl, pt, sizeof(pt));
    outptr += outl;
    encryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, ecb_ct128, sizeof(ecb_ct128)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(ecb_ct128))
    {
        return false;
    }
    return true;
}

static bool test_AES128EcbDecryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     decryptor          = EcbDecryptor<AES128>(user_key);
    uint8_t* outptr             = buffer;
    size_t   outl;
    decryptor.update(outptr, &outl, ecb_ct128, sizeof(ecb_ct128));
    outptr += outl;
    decryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, pt, sizeof(pt)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(pt))
    {
        return false;
    }
    return true;
}

static bool test_AES128CbcEncryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     encryptor          = CbcEncryptor<AES128>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    encryptor.update(outptr, &outl, pt, sizeof(pt));
    outptr += outl;
    encryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, cbc_ct128, sizeof(cbc_ct128)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(cbc_ct128))
    {
        return false;
    }
    return true;
}

static bool test_AES128CbcDecryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     decryptor          = CbcDecryptor<AES128>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    decryptor.update(outptr, &outl, cbc_ct128, sizeof(cbc_ct128));
    outptr += outl;
    decryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, pt, sizeof(pt)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(pt))
    {
        return false;
    }
    return true;
}

static bool test_AES128CfbEncryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     encryptor          = CfbEncryptor<AES128>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    encryptor.update(outptr, &outl, pt, sizeof(pt));
    outptr += outl;
    encryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, cfb_ct128, sizeof(cfb_ct128)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(cfb_ct128))
    {
        return false;
    }
    return true;
}

static bool test_AES128CfbDecryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     decryptor          = CfbDecryptor<AES128>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    decryptor.update(outptr, &outl, cfb_ct128, sizeof(cfb_ct128));
    outptr += outl;
    decryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, pt, sizeof(pt)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(pt))
    {
        return false;
    }
    return true;
}

static bool test_AES128OfbEncryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     encryptor          = OfbEncryptor<AES128>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    encryptor.update(outptr, &outl, pt, sizeof(pt));
    outptr += outl;
    encryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, ofb_ct128, sizeof(ofb_ct128)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(ofb_ct128))
    {
        return false;
    }
    return true;
}

static bool test_AES128OfbDecryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     decryptor          = OfbDecryptor<AES128>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    decryptor.update(outptr, &outl, ofb_ct128, sizeof(ofb_ct128));
    outptr += outl;
    decryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, pt, sizeof(pt)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(pt))
    {
        return false;
    }
    return true;
}

static bool test_AES128CtrEncryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     encryptor          = CtrEncryptor<AES128>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    encryptor.update(outptr, &outl, pt, sizeof(pt));
    outptr += outl;
    encryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, ctr_ct128, sizeof(ctr_ct128)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(ctr_ct128))
    {
        return false;
    }
    return true;
}

static bool test_AES128CtrDecryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     decryptor          = CtrDecryptor<AES128>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    decryptor.update(outptr, &outl, ctr_ct128, sizeof(ctr_ct128));
    outptr += outl;
    decryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, pt, sizeof(pt)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(pt))
    {
        return false;
    }
    return true;
}

#pragma endregion

// ****************************************
// ********** Test AES192 *****************
// ****************************************

#pragma region "AES192"

static uint8_t ct192[] = {
    0xd6, 0xb2, 0x9a, 0x9c, 0x59, 0x86, 0xd8, 0xe5, 0x02, 0xfd, 0xa2, 0x45,
    0x92, 0xdd, 0x2d, 0x3e, 0x23, 0xe8, 0x91, 0x8a, 0xa8, 0x13, 0xd3, 0x1d,
    0x48, 0xb5, 0x24, 0xdc, 0x77, 0x2c, 0xe5, 0xcd, 0xf2, 0xbc, 0xf5, 0xce,
    0xcb, 0x2b, 0x70, 0x94, 0x1d, 0x6c, 0xe8, 0x5f, 0xbc, 0xef, 0x9d, 0x21,
    0x56, 0xc6, 0x39, 0x5e, 0xcc, 0x07, 0xde, 0x20, 0xc7, 0xf5, 0xb7, 0x10,
    0x8b, 0x08, 0x5b, 0x15, 0x71, 0x7b, 0x79, 0x7d, 0x41, 0x01, 0xc8, 0xd5,
    0x94, 0xd1, 0x73, 0x02, 0x58, 0x1c, 0xbc, 0x64, 0x8e, 0x0e, 0xc8, 0x4d,
    0x29, 0xd9, 0x30, 0xdb, 0x57, 0x4d, 0xd5, 0x46, 0xd1, 0x0a, 0xd1, 0x3c,
    0x82, 0x67, 0x4f, 0x46, 0xb7, 0x6f, 0x03, 0x78, 0xba, 0x65, 0x69, 0x0d,
    0x33, 0x0e, 0xf5, 0xe7, 0x4e, 0xc7, 0x35, 0xb7, 0xcb, 0x2d, 0xb3, 0x7b,
    0xa4, 0x7e, 0xe9, 0x75, 0xa0, 0x7f, 0xe9, 0x1b,
};

static uint8_t ecb_ct192[] = {
    0xd6, 0xb2, 0x9a, 0x9c, 0x59, 0x86, 0xd8, 0xe5, 0x02, 0xfd, 0xa2, 0x45,
    0x92, 0xdd, 0x2d, 0x3e, 0x23, 0xe8, 0x91, 0x8a, 0xa8, 0x13, 0xd3, 0x1d,
    0x48, 0xb5, 0x24, 0xdc, 0x77, 0x2c, 0xe5, 0xcd, 0xf2, 0xbc, 0xf5, 0xce,
    0xcb, 0x2b, 0x70, 0x94, 0x1d, 0x6c, 0xe8, 0x5f, 0xbc, 0xef, 0x9d, 0x21,
    0x56, 0xc6, 0x39, 0x5e, 0xcc, 0x07, 0xde, 0x20, 0xc7, 0xf5, 0xb7, 0x10,
    0x8b, 0x08, 0x5b, 0x15, 0x71, 0x7b, 0x79, 0x7d, 0x41, 0x01, 0xc8, 0xd5,
    0x94, 0xd1, 0x73, 0x02, 0x58, 0x1c, 0xbc, 0x64, 0x8e, 0x0e, 0xc8, 0x4d,
    0x29, 0xd9, 0x30, 0xdb, 0x57, 0x4d, 0xd5, 0x46, 0xd1, 0x0a, 0xd1, 0x3c,
    0x82, 0x67, 0x4f, 0x46, 0xb7, 0x6f, 0x03, 0x78, 0xba, 0x65, 0x69, 0x0d,
    0x33, 0x0e, 0xf5, 0xe7, 0x4e, 0xc7, 0x35, 0xb7, 0xcb, 0x2d, 0xb3, 0x7b,
    0xa4, 0x7e, 0xe9, 0x75, 0xa0, 0x7f, 0xe9, 0x1b,
};

static uint8_t cbc_ct192[] = {
    0x01, 0x7b, 0xa7, 0xa3, 0x30, 0x34, 0x79, 0xb7, 0x1a, 0x1d, 0x0c, 0xa6,
    0xfb, 0x3c, 0x0c, 0xf8, 0x24, 0x23, 0x93, 0x16, 0xc2, 0xff, 0xb0, 0x1b,
    0x28, 0xb6, 0x6c, 0xf1, 0x46, 0xe7, 0xcd, 0x92, 0xbe, 0xda, 0xfc, 0x72,
    0x9c, 0xf2, 0x02, 0xd8, 0x55, 0x45, 0x19, 0x93, 0xad, 0x90, 0x5e, 0xe7,
    0xbd, 0x84, 0xfa, 0x19, 0x43, 0xb7, 0x4d, 0x49, 0x47, 0x94, 0xf2, 0xf5,
    0x36, 0x9e, 0x44, 0x7d, 0x28, 0xb4, 0x89, 0xf3, 0x9b, 0xf0, 0x17, 0xb2,
    0xae, 0x09, 0xfa, 0x09, 0x89, 0xe4, 0x1f, 0x48, 0xdc, 0xfc, 0xb9, 0xa9,
    0x7f, 0xc7, 0x77, 0x47, 0xd0, 0xef, 0x15, 0x35, 0xab, 0x4b, 0x86, 0x07,
    0xb7, 0x2a, 0xa5, 0x7d, 0xa9, 0x22, 0x7c, 0xe8, 0xa6, 0x8e, 0x55, 0x2b,
    0x71, 0x9b, 0xf0, 0x3a, 0x33, 0x66, 0xf4, 0x78, 0x16, 0x96, 0xbc, 0x51,
    0xa7, 0x5a, 0x7a, 0x92, 0xdc, 0xe9, 0xb8, 0xa8,
};

static uint8_t cfb_ct192[] = {
    0xb3, 0x4e, 0x9f, 0x0a, 0x57, 0xe3, 0xee, 0xa6, 0xc5, 0xad, 0xfc, 0x9b,
    0x7b, 0x7d, 0x43, 0x9c, 0xe4, 0x71, 0xb6, 0x3a, 0x6c, 0x7e, 0xf4, 0xeb,
    0x6c, 0xca, 0xf8, 0xc4, 0x92, 0x67, 0x0c, 0x29, 0x63, 0xb8, 0x8c, 0xa1,
    0xcb, 0x90, 0xab, 0x44, 0xf9, 0xea, 0x91, 0xbf, 0x02, 0x99, 0x92, 0x03,
    0xee, 0x1e, 0xbf, 0xdb, 0x39, 0xc7, 0x79, 0x1c, 0x9c, 0xe0, 0x70, 0x97,
    0x90, 0x3e, 0x71, 0x7d, 0x1d, 0x09, 0xb2, 0x8e, 0xca, 0x1d, 0x1b, 0x32,
    0xce, 0x21, 0x38, 0x62, 0xd7, 0x64, 0xd4, 0xab, 0x6f, 0xeb, 0x13, 0x18,
    0x4b, 0x6f, 0xa3, 0xe2, 0x54, 0x54, 0xd9, 0x53, 0x17, 0x4c, 0x5d, 0x68,
    0x3f, 0xa0, 0xef, 0x6f, 0xae, 0xc1, 0x53, 0x8f, 0xae, 0xcc, 0xad, 0x0e,
    0x0a, 0x68, 0xb1, 0xef, 0x63, 0xfa, 0x38, 0xa7, 0x2b, 0x79, 0x47, 0x98,
    0x05, 0x7d, 0x43, 0x61, 0x32, 0x08, 0x25, 0x1f,
};

static uint8_t ofb_ct192[] = {
    0xb3, 0x4e, 0x9f, 0x0a, 0x57, 0xe3, 0xee, 0xa6, 0xc5, 0xad, 0xfc, 0x9b,
    0x7b, 0x7d, 0x43, 0x9c, 0x6f, 0xce, 0xdc, 0x12, 0x89, 0x96, 0xde, 0x63,
    0x04, 0x37, 0x49, 0x8c, 0x79, 0x49, 0xb8, 0x05, 0x6d, 0x4d, 0x46, 0x56,
    0xfa, 0x99, 0x04, 0x35, 0xc2, 0x3a, 0xa2, 0xf9, 0x10, 0xb0, 0xa8, 0xea,
    0xa5, 0x3f, 0x67, 0xa0, 0x56, 0xde, 0xc5, 0xcb, 0x2c, 0x13, 0x4f, 0xe1,
    0x43, 0xd6, 0xd2, 0xea, 0x1a, 0x10, 0xdf, 0x15, 0xa6, 0x30, 0x77, 0xf9,
    0x72, 0xac, 0xe9, 0xff, 0x9f, 0x03, 0x43, 0xc2, 0xf3, 0xcd, 0x09, 0x6f,
    0x26, 0xa2, 0xde, 0x99, 0x8a, 0x9b, 0x97, 0x90, 0x21, 0x80, 0xc5, 0xc9,
    0x09, 0xdd, 0x94, 0xc9, 0x77, 0xfd, 0xb9, 0x3b, 0x05, 0x37, 0x55, 0x7a,
    0x8b, 0xb4, 0xc6, 0xa2, 0x40, 0xc3, 0x7b, 0x90, 0x05, 0x98, 0x71, 0x94,
    0xfc, 0x85, 0x82, 0xc1, 0x65, 0x68, 0xcd, 0xe2,
};

static uint8_t ctr_ct192[] = {
    0xb3, 0x4e, 0x9f, 0x0a, 0x57, 0xe3, 0xee, 0xa6, 0xc5, 0xad, 0xfc, 0x9b,
    0x7b, 0x7d, 0x43, 0x9c, 0xa0, 0x72, 0x6b, 0x2f, 0xd4, 0xad, 0x27, 0x26,
    0x0d, 0x0b, 0x9e, 0x29, 0x2f, 0x98, 0x35, 0xfc, 0x8d, 0x69, 0x21, 0x22,
    0xb0, 0x60, 0x0f, 0xca, 0x23, 0x85, 0x61, 0x05, 0x1c, 0xa2, 0x09, 0x6f,
    0x95, 0x17, 0x6f, 0x1b, 0xfc, 0xab, 0x75, 0x9f, 0x1f, 0x7b, 0x3c, 0x11,
    0xed, 0x63, 0xd2, 0x94, 0xe7, 0x5b, 0xac, 0xd7, 0xcc, 0x2f, 0x7b, 0xcb,
    0x89, 0x89, 0xac, 0x34, 0xb5, 0xed, 0x9f, 0x6a, 0x06, 0x0d, 0xc2, 0x17,
    0xe6, 0xfe, 0x90, 0x19, 0x55, 0x10, 0x0a, 0x3b, 0x3c, 0x2a, 0xb9, 0xf3,
    0x8f, 0xe6, 0xba, 0x18, 0x48, 0x5f, 0x05, 0x77, 0x32, 0x07, 0xb3, 0x58,
    0xfe, 0xef, 0x30, 0x83, 0x11, 0x80, 0xc1, 0x12, 0xe2, 0x3c, 0xc2, 0x3f,
    0x19, 0x6a, 0x76, 0x6b, 0x69, 0x84, 0xeb, 0x2b,
};

static bool test_AES192EcbEncryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     encryptor          = EcbEncryptor<AES192>(user_key);
    uint8_t* outptr             = buffer;
    size_t   outl;
    encryptor.update(outptr, &outl, pt, sizeof(pt));
    outptr += outl;
    encryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, ecb_ct192, sizeof(ecb_ct192)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(ecb_ct192))
    {
        return false;
    }
    return true;
}

static bool test_AES192EcbDecryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     decryptor          = EcbDecryptor<AES192>(user_key);
    uint8_t* outptr             = buffer;
    size_t   outl;
    decryptor.update(outptr, &outl, ecb_ct192, sizeof(ecb_ct192));
    outptr += outl;
    decryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, pt, sizeof(pt)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(pt))
    {
        return false;
    }
    return true;
}

static bool test_AES192CbcEncryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     encryptor          = CbcEncryptor<AES192>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    encryptor.update(outptr, &outl, pt, sizeof(pt));
    outptr += outl;
    encryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, cbc_ct192, sizeof(cbc_ct192)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(cbc_ct192))
    {
        return false;
    }
    return true;
}

static bool test_AES192CbcDecryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     decryptor          = CbcDecryptor<AES192>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    decryptor.update(outptr, &outl, cbc_ct192, sizeof(cbc_ct192));
    outptr += outl;
    decryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, pt, sizeof(pt)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(pt))
    {
        return false;
    }
    return true;
}

static bool test_AES192CfbEncryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     encryptor          = CfbEncryptor<AES192>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    encryptor.update(outptr, &outl, pt, sizeof(pt));
    outptr += outl;
    encryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, cfb_ct192, sizeof(cfb_ct192)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(cfb_ct192))
    {
        return false;
    }
    return true;
}

static bool test_AES192CfbDecryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     decryptor          = CfbDecryptor<AES192>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    decryptor.update(outptr, &outl, cfb_ct192, sizeof(cfb_ct192));
    outptr += outl;
    decryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, pt, sizeof(pt)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(pt))
    {
        return false;
    }
    return true;
}

static bool test_AES192OfbEncryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     encryptor          = OfbEncryptor<AES192>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    encryptor.update(outptr, &outl, pt, sizeof(pt));
    outptr += outl;
    encryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, ofb_ct192, sizeof(ofb_ct192)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(ofb_ct192))
    {
        return false;
    }
    return true;
}

static bool test_AES192OfbDecryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     decryptor          = OfbDecryptor<AES192>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    decryptor.update(outptr, &outl, ofb_ct192, sizeof(ofb_ct192));
    outptr += outl;
    decryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, pt, sizeof(pt)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(pt))
    {
        return false;
    }
    return true;
}

static bool test_AES192CtrEncryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     encryptor          = CtrEncryptor<AES192>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    encryptor.update(outptr, &outl, pt, sizeof(pt));
    outptr += outl;
    encryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, ctr_ct192, sizeof(ctr_ct192)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(ctr_ct192))
    {
        return false;
    }
    return true;
}

static bool test_AES192CtrDecryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     decryptor          = CtrDecryptor<AES192>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    decryptor.update(outptr, &outl, ctr_ct192, sizeof(ctr_ct192));
    outptr += outl;
    decryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, pt, sizeof(pt)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(pt))
    {
        return false;
    }
    return true;
}

#pragma endregion

// ****************************************
// ********** Test AES256 *****************
// ****************************************

#pragma region "AES256"

static uint8_t ct256[] = {
    0xb8, 0x7b, 0xc6, 0xea, 0x26, 0x48, 0x03, 0x4c, 0x6d, 0xf5, 0xfa, 0x38,
    0x0b, 0x7f, 0xb3, 0x30, 0x8f, 0xf9, 0xd4, 0xd0, 0xeb, 0x83, 0xd5, 0x97,
    0xce, 0x62, 0xb6, 0xe6, 0x80, 0x89, 0xd8, 0xca, 0x5c, 0x94, 0x6c, 0x46,
    0x1c, 0x74, 0x50, 0xaa, 0xb1, 0x7e, 0x44, 0x17, 0x63, 0xad, 0xf1, 0x69,
    0x2e, 0xd1, 0x6f, 0xbe, 0x95, 0x67, 0x44, 0x91, 0xae, 0x15, 0x49, 0x6c,
    0xca, 0xc5, 0xb2, 0x79, 0x87, 0x5e, 0x9b, 0xb2, 0x1f, 0x96, 0xc8, 0xd0,
    0xcf, 0xbf, 0x20, 0x67, 0x37, 0xfe, 0xe6, 0x24, 0x1f, 0xa3, 0xa3, 0x41,
    0xad, 0x6a, 0xb6, 0x4f, 0x83, 0xa9, 0xf9, 0xa3, 0x64, 0x0f, 0x38, 0x24,
    0xac, 0x0b, 0x17, 0x11, 0xe3, 0x2e, 0xac, 0x2b, 0x23, 0x5d, 0x72, 0xc8,
    0x4b, 0x61, 0x45, 0x37, 0x52, 0x90, 0xca, 0xb3, 0xed, 0x47, 0x3c, 0xb2,
    0x90, 0x84, 0xae, 0xf2, 0x60, 0x1d, 0xaa, 0xdf,
};

static uint8_t ecb_ct256[] = {
    0xb8, 0x7b, 0xc6, 0xea, 0x26, 0x48, 0x03, 0x4c, 0x6d, 0xf5, 0xfa, 0x38,
    0x0b, 0x7f, 0xb3, 0x30, 0x8f, 0xf9, 0xd4, 0xd0, 0xeb, 0x83, 0xd5, 0x97,
    0xce, 0x62, 0xb6, 0xe6, 0x80, 0x89, 0xd8, 0xca, 0x5c, 0x94, 0x6c, 0x46,
    0x1c, 0x74, 0x50, 0xaa, 0xb1, 0x7e, 0x44, 0x17, 0x63, 0xad, 0xf1, 0x69,
    0x2e, 0xd1, 0x6f, 0xbe, 0x95, 0x67, 0x44, 0x91, 0xae, 0x15, 0x49, 0x6c,
    0xca, 0xc5, 0xb2, 0x79, 0x87, 0x5e, 0x9b, 0xb2, 0x1f, 0x96, 0xc8, 0xd0,
    0xcf, 0xbf, 0x20, 0x67, 0x37, 0xfe, 0xe6, 0x24, 0x1f, 0xa3, 0xa3, 0x41,
    0xad, 0x6a, 0xb6, 0x4f, 0x83, 0xa9, 0xf9, 0xa3, 0x64, 0x0f, 0x38, 0x24,
    0xac, 0x0b, 0x17, 0x11, 0xe3, 0x2e, 0xac, 0x2b, 0x23, 0x5d, 0x72, 0xc8,
    0x4b, 0x61, 0x45, 0x37, 0x52, 0x90, 0xca, 0xb3, 0xed, 0x47, 0x3c, 0xb2,
    0x90, 0x84, 0xae, 0xf2, 0x60, 0x1d, 0xaa, 0xdf,
};

static uint8_t cbc_ct256[] = {
    0xc1, 0x78, 0xbc, 0x39, 0xcb, 0x42, 0x00, 0xef, 0x37, 0xce, 0x62, 0x74,
    0xc4, 0x1d, 0x28, 0xf2, 0x51, 0x7d, 0xc5, 0x1b, 0x0a, 0xb0, 0xcb, 0x9c,
    0x45, 0x58, 0x5d, 0x89, 0x57, 0x06, 0xaa, 0xea, 0x49, 0x7c, 0x95, 0xea,
    0xd7, 0x55, 0x44, 0x5c, 0xe3, 0xc7, 0x8e, 0x52, 0x16, 0x53, 0x24, 0x96,
    0x44, 0xe3, 0x3e, 0x0d, 0xfd, 0xe9, 0xc0, 0xa0, 0xfc, 0x80, 0xb6, 0x8b,
    0x03, 0xfd, 0xc4, 0xc9, 0x22, 0x0d, 0xa7, 0xe3, 0x8a, 0x37, 0x26, 0xad,
    0xe1, 0x8f, 0x6a, 0x28, 0x43, 0x3d, 0x66, 0xa7, 0x6c, 0x70, 0xd4, 0xce,
    0x3c, 0xec, 0xd2, 0xa4, 0x71, 0x93, 0x89, 0x16, 0xe1, 0x0b, 0x94, 0x54,
    0x3b, 0x5a, 0xba, 0xbf, 0x3d, 0xe9, 0x73, 0x52, 0xbd, 0x0b, 0xcb, 0xb6,
    0x30, 0xd6, 0xa5, 0x13, 0x5d, 0x2e, 0xa9, 0x96, 0xd3, 0xfe, 0x1f, 0xae,
    0x6b, 0xe5, 0x01, 0x95, 0xe3, 0xfb, 0x6f, 0x5a,
};

static uint8_t cfb_ct256[] = {
    0x4f, 0xab, 0x3d, 0x81, 0x72, 0x9e, 0x6a, 0xb0, 0x49, 0xf0, 0x9b, 0x5a,
    0xd5, 0x2b, 0x61, 0xf5, 0x1e, 0x66, 0x50, 0xb8, 0x83, 0x02, 0xfd, 0x3a,
    0x43, 0xc0, 0x94, 0x1b, 0x14, 0xd7, 0x26, 0x27, 0xe2, 0xb2, 0xf9, 0x32,
    0x3e, 0xd4, 0xc5, 0xe4, 0xa4, 0x70, 0xfa, 0x1a, 0xe1, 0x97, 0x1a, 0x95,
    0x57, 0x15, 0x8e, 0x34, 0x72, 0xd8, 0x30, 0x22, 0xee, 0xbd, 0x84, 0x45,
    0xb9, 0xae, 0xba, 0x96, 0xf0, 0xe7, 0xd4, 0x60, 0x96, 0xb3, 0xdc, 0xbb,
    0x2d, 0x7e, 0xf9, 0xcc, 0xab, 0xca, 0x71, 0x31, 0x2a, 0x94, 0xbd, 0x57,
    0x56, 0x08, 0xad, 0xc5, 0x09, 0xab, 0x40, 0x20, 0xb5, 0xed, 0x7a, 0xe5,
    0x2b, 0xc7, 0x4e, 0xae, 0x23, 0xf2, 0xae, 0x05, 0x29, 0x33, 0x42, 0x77,
    0x32, 0x33, 0x91, 0xda, 0x71, 0x12, 0xdb, 0x81, 0x06, 0xe3, 0x84, 0x21,
    0xc0, 0x82, 0xf6, 0x1a, 0x1a, 0x31, 0x5a, 0xf8,
};

static uint8_t ofb_ct256[] = {
    0x4f, 0xab, 0x3d, 0x81, 0x72, 0x9e, 0x6a, 0xb0, 0x49, 0xf0, 0x9b, 0x5a,
    0xd5, 0x2b, 0x61, 0xf5, 0x30, 0x3f, 0x40, 0x02, 0xca, 0x2c, 0x39, 0xb8,
    0xac, 0x9c, 0xe1, 0x58, 0xe8, 0xf5, 0x13, 0x87, 0x4d, 0x72, 0x88, 0x0d,
    0x04, 0x12, 0xfb, 0x92, 0x22, 0xcb, 0x7c, 0x3e, 0xf5, 0x9f, 0x95, 0xfa,
    0xe4, 0x69, 0xfd, 0xad, 0xc1, 0x0e, 0x22, 0xc2, 0x0b, 0xf0, 0xd4, 0xd5,
    0x2e, 0x17, 0x97, 0xdf, 0xae, 0xee, 0xe3, 0xd2, 0x27, 0x62, 0xaa, 0xb5,
    0x67, 0xa8, 0x92, 0xfe, 0x08, 0xf4, 0x45, 0x09, 0x4b, 0xbd, 0xcc, 0x8f,
    0x68, 0x39, 0x49, 0x88, 0x43, 0x6a, 0xd9, 0x0b, 0x2f, 0xed, 0x0b, 0x1b,
    0xf2, 0x1e, 0x6d, 0x04, 0x62, 0x19, 0x74, 0x4c, 0xef, 0x52, 0xb4, 0x2a,
    0x38, 0x8d, 0x5d, 0x34, 0x28, 0xe1, 0x89, 0xef, 0xf7, 0xb0, 0xce, 0xa6,
    0x2c, 0x17, 0xfc, 0x3e, 0xd7, 0xa9, 0x88, 0xb4,
};

static uint8_t ctr_ct256[] = {
    0x4f, 0xab, 0x3d, 0x81, 0x72, 0x9e, 0x6a, 0xb0, 0x49, 0xf0, 0x9b, 0x5a,
    0xd5, 0x2b, 0x61, 0xf5, 0xfb, 0x82, 0x7e, 0x1e, 0x9d, 0x34, 0x16, 0x12,
    0x2e, 0x9c, 0xda, 0xbd, 0x13, 0xbf, 0xa6, 0x28, 0x62, 0x5c, 0xc5, 0xf8,
    0x87, 0xa8, 0x0f, 0x7a, 0xe3, 0x87, 0xf9, 0x41, 0x51, 0xd3, 0xe3, 0xf8,
    0xa4, 0xcb, 0xc5, 0xb1, 0x12, 0x31, 0x0c, 0x20, 0xfb, 0x62, 0x84, 0x24,
    0x8f, 0xf3, 0x1a, 0x99, 0x52, 0x91, 0xe6, 0xbc, 0x50, 0x68, 0xfb, 0xc2,
    0x73, 0xcc, 0xe9, 0x70, 0x18, 0xe3, 0xf0, 0x15, 0x82, 0xb8, 0x81, 0xb7,
    0x1a, 0xb9, 0xbb, 0xa5, 0x13, 0x8c, 0x01, 0xb7, 0xa7, 0xe8, 0x68, 0x9b,
    0xb9, 0x3f, 0xd0, 0x86, 0x6c, 0xff, 0xdc, 0x02, 0xd7, 0x99, 0xed, 0xdb,
    0x17, 0x55, 0x5f, 0x75, 0x39, 0xf6, 0xec, 0xbd, 0xc2, 0xd1, 0x60, 0x4e,
    0xfa, 0xaf, 0x94, 0xd8, 0xd1, 0xf8, 0x85, 0x07,
};

static bool test_AES256EcbEncryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     encryptor          = EcbEncryptor<AES256>(user_key);
    uint8_t* outptr             = buffer;
    size_t   outl;
    encryptor.update(outptr, &outl, pt, sizeof(pt));
    outptr += outl;
    encryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, ecb_ct256, sizeof(ecb_ct256)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(ecb_ct256))
    {
        return false;
    }
    return true;
}

static bool test_AES256EcbDecryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     decryptor          = EcbDecryptor<AES256>(user_key);
    uint8_t* outptr             = buffer;
    size_t   outl;
    decryptor.update(outptr, &outl, ecb_ct256, sizeof(ecb_ct256));
    outptr += outl;
    decryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, pt, sizeof(pt)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(pt))
    {
        return false;
    }
    return true;
}

static bool test_AES256CbcEncryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     encryptor          = CbcEncryptor<AES256>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    encryptor.update(outptr, &outl, pt, sizeof(pt));
    outptr += outl;
    encryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, cbc_ct256, sizeof(cbc_ct256)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(cbc_ct256))
    {
        return false;
    }
    return true;
}

static bool test_AES256CbcDecryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     decryptor          = CbcDecryptor<AES256>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    decryptor.update(outptr, &outl, cbc_ct256, sizeof(cbc_ct256));
    outptr += outl;
    decryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, pt, sizeof(pt)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(pt))
    {
        return false;
    }
    return true;
}

static bool test_AES256CfbEncryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     encryptor          = CfbEncryptor<AES256>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    encryptor.update(outptr, &outl, pt, sizeof(pt));
    outptr += outl;
    encryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, cfb_ct256, sizeof(cfb_ct256)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(cfb_ct256))
    {
        return false;
    }
    return true;
}

static bool test_AES256CfbDecryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     decryptor          = CfbDecryptor<AES256>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    decryptor.update(outptr, &outl, cfb_ct256, sizeof(cfb_ct256));
    outptr += outl;
    decryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, pt, sizeof(pt)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(pt))
    {
        return false;
    }
    return true;
}

static bool test_AES256OfbEncryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     encryptor          = OfbEncryptor<AES256>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    encryptor.update(outptr, &outl, pt, sizeof(pt));
    outptr += outl;
    encryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, ofb_ct256, sizeof(ofb_ct256)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(ofb_ct256))
    {
        return false;
    }
    return true;
}

static bool test_AES256OfbDecryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     decryptor          = OfbDecryptor<AES256>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    decryptor.update(outptr, &outl, ofb_ct256, sizeof(ofb_ct256));
    outptr += outl;
    decryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, pt, sizeof(pt)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(pt))
    {
        return false;
    }
    return true;
}

static bool test_AES256CtrEncryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     encryptor          = CtrEncryptor<AES256>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    encryptor.update(outptr, &outl, pt, sizeof(pt));
    outptr += outl;
    encryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, ctr_ct256, sizeof(ctr_ct256)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(ctr_ct256))
    {
        return false;
    }
    return true;
}

static bool test_AES256CtrDecryptor()
{
    uint8_t  buffer[sizeof(pt)] = {0};
    auto     decryptor          = CtrDecryptor<AES256>(user_key, iv);
    uint8_t* outptr             = buffer;
    size_t   outl;
    decryptor.update(outptr, &outl, ctr_ct256, sizeof(ctr_ct256));
    outptr += outl;
    decryptor.do_final(outptr, &outl);
    outptr += outl;
    if (std::memcmp(buffer, pt, sizeof(pt)) != 0 ||
        (size_t)(outptr - buffer) != sizeof(pt))
    {
        return false;
    }
    return true;
}

#pragma endregion
